﻿/*-----------------------------------------------
// File: Story3dLoader.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;

namespace AssetLoad
{
    public class Story3dLoader : LoaderBase
    {
        public override string GetPrefix() {
            return @"Story3d/";
        }

        public IEnumerator LoadStory(string resourceName, LoadComplete callback)
        {
            string abName = GetPrefix() + resourceName;
            AssetBundleManager.Instance.LoadAssetBundle(abName);
            while (!AssetBundleManager.Instance.IsLoadedAssetBundle(abName))
            {
                yield return null;
            }

            if (callback != null)
            {
                var obj = AssetBundleManager.Instance.GetAssetFromBundle(abName, resourceName, typeof(GameObject));
                callback(GameObject.Instantiate(obj));
            }
        }

        public void UnloadStory(GameObject obj, string resourceName) {
            GameObject.Destroy(obj);
            string abName = GetPrefix() + resourceName;
            AssetBundleManager.Instance.UnloadAssetBundle(abName);
        }
    }
}